var config = require('../../utils/config.js');
var netutil = require('../../utils/netutil.js');
var baseutil = require('../../utils/baseutil.js');
let { WeToast } = require('../../src/wetoast.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currenntSelect: 0,//当前选择的
    TravelStandard: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getStandard();
    //创建可重复使用的toast实例，并附加到this上，通过this.wetoast访问
    new app.WeToast()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getStandard() {
    var THIS = this
    var url = config.getBaseUrl("CommonApi", "GetTravelStandard");

    var Data = new Object();
    Data.UserID = app.globalData.TUserInfo.UserID

    baseutil.log(url);
    netutil.post(
      url, Data,
      function (res) {
        baseutil.log(res.data);
        if (res.data.ResponseMetaInfo.StatusCode == '0') {
          var tempTravelStandard = res.data.Data.TravelStandard;

          var trainTypeList = tempTravelStandard.TrainLimit.split("|")
          var trainTypeText = "";
          //无座 = 1,硬座 = 2,硬座 = 2,软座 = 3,硬卧 = 4,软卧 = 5,高级软卧 = 6,二等座 = 7,一等座 = 8,特等座 = 9,商务座 = 10
          for (var i = 0; i < trainTypeList.length; i++) {
            switch (parseInt(trainTypeList[i])) {
              case 1:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "无座;";
                } else {
                  trainTypeText += "无座";
                }
                break;
              case 2:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "硬座;";
                } else {
                  trainTypeText += "硬座";
                }
                break;
              case 3:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "软座;";
                } else {
                  trainTypeText += "软座";
                }
                break;
              case 4:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "硬卧;";
                } else {
                  trainTypeText += "硬卧";
                }
                break;
              case 5:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "软卧;";
                } else {
                  trainTypeText += "软卧";
                }
                break;
              case 6:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "高级软卧;";
                } else {
                  trainTypeText += "高级软卧";
                }
                break;
              case 7:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "二等座;";
                } else {
                  trainTypeText += "二等座";
                }
                break;
              case 8:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "一等座;";
                } else {
                  trainTypeText += "一等座";
                }
                break;
              case 9:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "特等座;";
                } else {
                  trainTypeText += "特等座";
                }
                break;
              case 10:
                if (i != trainTypeList.length - 1) {
                  trainTypeText += "商务座;";
                } else {
                  trainTypeText += "商务座";
                }
                break;

            }
          }
          tempTravelStandard.trainTypeText = trainTypeText;


          THIS.setData({
            TravelStandard: tempTravelStandard
          })
        } else {
          THIS.wetoast.toast({
            title: res.data.ResponseMetaInfo.Reason,
            duration: 1000
          })
        }
      })
  },
  selectTab(e) {
    var position = e.currentTarget.dataset.position
    this.setData({
      currenntSelect: position
    })
  }
})